import launch
from launch.substitutions import Command, LaunchConfiguration
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from ament_index_python.packages import get_package_share_directory
from nav2_common.launch import RewrittenYaml
import launch_ros
from launch.actions import TimerAction
import os

def generate_launch_description():

    map_pub_cmd=launch_ros.actions.Node(
            package='global_planner',
            executable='map_publisher',
            name='map_publisher',
            parameters=[{'map_path': LaunchConfiguration('map_path')}],
            output='screen'
    )

    global_planner_cmd=launch_ros.actions.Node(
            package='global_planner',
            executable='global_planner',
            name='global_planner',
            output='screen'
    )

    return launch.LaunchDescription([
        launch.actions.DeclareLaunchArgument(name='map_path', default_value='my_map.pgm',
                                            description='Absolute path to map file'),
        global_planner_cmd,
        TimerAction(period=1.0, actions=[map_pub_cmd]),
    ])
